{extend name="public/layout" /}
{block name="body"}
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <table id="admin-table" lay-filter="data-list"></table>
            </div>
        </div>
    </div>
{/block}
{block name="script"}
    <script src="/static/admin/js/action.js?v={$version}"></script>
    <script type="text/html" id="row-handler">
        <input data-id='{{ d.id }}'
                {{#  if(d.is_use == 1){ }}
               checked
               {{#  } }}
               type="checkbox" lay-filter="update_status" lay-skin="switch" lay-text="通过|失败">
    </script>
    <script>
        layui.use(['table','form'], function(){
            var table = layui.table;
            var form = layui.form;
            $ = layui.$;
            table.render({
                elem: '#admin-table'
                ,url: '{:url('index')}'
                ,page: true
                ,cols: [[
                    {field: 'id', width:60,title: 'ID'}
                    ,{field: 'mobile',width:140, title: '手机号码'}
                    ,{field: 'handler', title: '操作',toolbar:'#row-handler'}
                ]]
                ,parseData: function(res){
                    return {
                        "code": res.code,
                        "msg": res.message,
                        "count": res.data.total,
                        "data": res.data.data
                    };
                }
                ,response: {
                    statusCode: 10000
                }
            });

            form.on('switch(update_status)', function(data){
                var now = $(this).prop('checked');
                var url = "{:url('update_status')}";
                var d = new Object();
                var _this = this;
                d.id = $(this).attr('data-id');
                if(now){
                    d.status = 1;
                }else{
                    d.status = 0;

                }
                $.post(url,d,function(data){
                    if(data.code != 10000){
                        if(now){
                            $(_this).removeAttr('checked');
                        }else{
                            $(_this).attr('checked',true);

                        }
                        layer.msg(data.msg,{icon:2,time:1500})
                    }
                    form.render('checkbox');
                });

            });

        });
    </script>
{/block}